<?
  include(dirname(__FILE__) . "/database.inc.php");
  $db = new database(dirname(__FILE__) . "/streaming.rdb");

  $r = array_shift($db->query("SELECT * FROM track WHERE serial = ?", array($_REQUEST['trackid'])));
  $filename = $r['filename'];

//Set directory so pear packages work properly
  chdir("/home2/gurumike/php");

//Delete file from s3
  require_once("Services/Amazon/S3.php");
  $s3 = Services_Amazon_S3::getAccount("AKIAJIZQG4MAPIGZRPCA", "dmdEV6R42oVPq7KCg/2i1ZnjYY98pLYv74KT/jyF");
  $bucket = $s3->getBucket("rdp-music");
  $object = $bucket->getObject($filename);
  if($object->load()) $object->delete();

//Delete record from DB
  $db->execute("DELETE FROM track WHERE serial = ?", array($_REQUEST['trackid']));
?>
